<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    </el-row>

    <el-table v-loading="loading" :data="switchList" >
      <el-table-column label="普通商品余额开关" align="center" prop="showBalanceSwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.showBalanceSwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.showBalanceSwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="普通商品微信支付开关" align="center" prop="showWechatSwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.showWechatSwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.showWechatSwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="普通商品支付宝支付开关" align="center" prop="showAlipaySwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.showAlipaySwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.showAlipaySwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>
    <el-table v-loading="loading" :data="switchList" >
      <el-table-column label="惠选商品余额开关" align="center" prop="hxBalanceSwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.hxBalanceSwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.hxBalanceSwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="惠选商品微信支付开关" align="center" prop="hxWechatSwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.hxWechatSwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.hxWechatSwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="惠选商品支付宝支付开关" align="center" prop="hxAlipaySwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.hxAlipaySwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.hxAlipaySwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>

    <el-table v-loading="loading" :data="switchList" >
      <el-table-column label="兑换区商品余额开关" align="center" prop="exBalanceSwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.exBalanceSwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.exBalanceSwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="兑换区商品微信支付开关" align="center" prop="exWechatSwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.exWechatSwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.exWechatSwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="兑换区商品支付宝支付开关" align="center" prop="exAlipaySwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.exAlipaySwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.exAlipaySwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>
    <el-table v-loading="loading" :data="switchList" >
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      <el-table-column label="余额支付开关" align="center" prop="balanceSwitch" v-if="form.balanceSwitch === 0">-->
<!--        <template slot-scope="scope">-->
<!--          关-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="余额支付开关" align="center" prop="balanceSwitch" v-else>-->
<!--        <template slot-scope="scope">-->
<!--          开-->
<!--        </template>-->
<!--      </el-table-column>-->

      <el-table-column label="余额开关" align="center" prop="balanceSwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.balanceSwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.balanceSwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="余额转积分开关" align="center" prop="balanceExchangeAssport">
        <template slot-scope="scope">
          <el-tag :type="scope.row.balanceExchangeAssport === 0 ? 'danger' : 'success'">
            {{ scope.row.balanceExchangeAssport === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="发送消费额功能开关" align="center" prop="sendCnhdFunction">
        <template slot-scope="scope">
          <el-tag :type="scope.row.sendCnhdFunction === 0 ? 'danger' : 'success'">
            {{ scope.row.sendCnhdFunction === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="微信支付开关" align="center" prop="wechatPaymentSwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.wechatPaymentSwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.wechatPaymentSwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="支付宝支付开关" align="center" prop="alipayPaymentSwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.alipayPaymentSwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.alipayPaymentSwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

      <el-table-column label="看广告释放积分开关" align="center" prop="advReleaseSwitch">
        <template slot-scope="scope">
          <el-tag :type="scope.row.advReleaseSwitch === 0 ? 'danger' : 'success'">
            {{ scope.row.advReleaseSwitch === 0 ? '关' : '开' }}
          </el-tag>
        </template>
      </el-table-column>

<!--      <el-table-column label="余额转积分开关" align="center" prop="balanceExchangeAssport" />-->
<!--      <el-table-column label="余额转积分开关" align="center" prop="balanceExchangeAssport" v-if="form.balanceExchangeAssport === 0">-->
<!--        <template slot-scope="scope">-->
<!--          关-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="余额转积分开关" align="center" prop="balanceExchangeAssport" v-else>-->
<!--        <template slot-scope="scope">-->
<!--          开-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="发送消费额功能开关键" align="center" prop="sendCnhdFunction" />-->
<!--      <el-table-column label="发送消费额功能开关" align="center" prop="sendCnhdFunction" v-if="form.sendCnhdFunction === 0">-->
<!--        <template slot-scope="scope">-->
<!--          关-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="发送消费额功能开关" align="center" prop="sendCnhdFunction" v-else>-->
<!--        <template slot-scope="scope">-->
<!--          开-->
<!--        </template>-->
<!--      </el-table-column>-->

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改余额支付开关对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="余额开关" prop="balanceSwitch">
<!--              <el-input v-model="form.balanceSwitch" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.balanceSwitch" :label="0">关</el-radio>
              <el-radio v-model="form.balanceSwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="余额转积分开关" prop="balanceExchangeAssport">
<!--              <el-input v-model="form.balanceExchangeAssport" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.balanceExchangeAssport" :label="0">关</el-radio>
              <el-radio v-model="form.balanceExchangeAssport" :label="1" >开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="发送消费额功能开关" prop="sendCnhdFunction">
<!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.sendCnhdFunction" :label="0">关</el-radio>
              <el-radio v-model="form.sendCnhdFunction" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="微信支付开关" prop="wechatPaymentSwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.wechatPaymentSwitch" :label="0">关</el-radio>
              <el-radio v-model="form.wechatPaymentSwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="支付宝支付开关" prop="alipayPaymentSwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.alipayPaymentSwitch" :label="0">关</el-radio>
              <el-radio v-model="form.alipayPaymentSwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row>
          <el-col :span="24">
            <el-form-item label="普通区余额支付开关" prop="showBalanceSwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.showBalanceSwitch" :label="0">关</el-radio>
              <el-radio v-model="form.showBalanceSwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="普通区支付宝支付开关" prop="showAlipaySwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.showAlipaySwitch" :label="0">关</el-radio>
              <el-radio v-model="form.showAlipaySwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="普通区微信支付开关" prop="showWechatSwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.showWechatSwitch" :label="0">关</el-radio>
              <el-radio v-model="form.showWechatSwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="惠选区余额支付开关" prop="hxBalanceSwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.hxBalanceSwitch" :label="0">关</el-radio>
              <el-radio v-model="form.hxBalanceSwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="惠选区支付宝支付开关" prop="hxAlipaySwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.hxAlipaySwitch" :label="0">关</el-radio>
              <el-radio v-model="form.hxAlipaySwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="惠选区微信支付开关" prop="hxWechatSwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.hxWechatSwitch" :label="0">关</el-radio>
              <el-radio v-model="form.hxWechatSwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="兑换区余额支付开关" prop="exBalanceSwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.exBalanceSwitch" :label="0">关</el-radio>
              <el-radio v-model="form.exBalanceSwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="兑换区微信支付开关" prop="exWechatSwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.exWechatSwitch" :label="0">关</el-radio>
              <el-radio v-model="form.exWechatSwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="兑换区支付宝支付开关" prop="exAlipaySwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.exAlipaySwitch" :label="0">关</el-radio>
              <el-radio v-model="form.exAlipaySwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="看广告释放积分开关" prop="advReleaseSwitch">
              <!--              <el-input v-model="form.sendCnhdFunction" placeholder="请输入用户昵称" maxlength="30" />-->
              <el-radio v-model="form.advReleaseSwitch" :label="0">关</el-radio>
              <el-radio v-model="form.advReleaseSwitch" :label="1">开</el-radio>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import switchApi from '@/api/switchApi.js'
export default {
  // name: "Switch",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 余额支付开关表格数据
      switchList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询余额支付开关列表 */
    // getList() {
    //   this.loading = true;
    //   listSwitch(this.queryParams).then(response => {
    //     this.switchList = response.rows;
    //     this.total = response.total;
    //     this.loading = false;
    //   });
    // },
    getList () {
      switchApi.listSwitch(this.pamars).then(res => {
        if (res && res.data.code == 200) {
          this.switchList = res.data.data
          console.log(res)
          // this.totalPage = res.data.page.totalCount
        }
        this.loading = false;
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        balanceSwitch: null,
        balanceExchangeAssport: null,
        sendCnhdFunction: null,
        wechatPaymentSwitch: null,
        alipayPaymentSwitch: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加余额支付开关";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      switchApi.SwitchById(id).then(response => {
        this.form = response.data.data;
        this.open = true;
        this.title = "修改余额支付开关";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            switchApi.updateSwitch(this.form).then(response => {
              this.$message.success("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            switchApi.addSwitch(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除余额支付开关编号为"' + ids + '"的数据项？').then(function() {
        return delSwitch(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/switch/export', {
        ...this.queryParams
      }, `switch_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
